package com.zhangsun.springShiro.system.controller;


import com.zhangsun.springShiro.base.bean.ResponseData;
import com.zhangsun.springShiro.system.bean.UserEdit;
import com.zhangsun.springShiro.system.entity.UserEntity;
import com.zhangsun.springShiro.system.service.UserService;
import com.zhangsun.springShiro.common.utils.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author zhangsun
 * @since 2019-07-23
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 创建admin
     *
     * @return 结果
     */
    @RequiresPermissions("create:admin")
    @RequestMapping("/createAdmin")
    public ResponseData createAdmin() {
        userService.createAdmin();
        return ResponseUtil.success();
    }

    @PostMapping("/createUser")
    public ResponseData createUser(UserEdit edit) {
        userService.createUser(edit);
        return ResponseUtil.success();
    }

    @RequiresPermissions("system:user:view")
    @RequestMapping("/findAll")
    public ResponseData findAll() {
        List<UserEntity> list = userService.findAll();
        return ResponseUtil.success(list);
    }

}
